package com.atguigu.gulimall.member.exception;

import com.atguigu.common.exception.BizCodeEnum;
import com.atguigu.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
@ControllerAdvice
public class GulimallExceptionControllerAdvice {

    @ExceptionHandler(value = Exception.class)
    public R handlerException(Exception e) {
        log.error("系统异常:{}" + e);
        return R.error();
    }

    @ExceptionHandler(value = PhoneException.class)
    public R handlerPhoneException(PhoneException e) {
        log.error("手机号码验证异常{}" + e);
        return R.error(BizCodeEnum.PHONE_EXIST_EXCEPTION.getCode(), BizCodeEnum.PHONE_EXIST_EXCEPTION.getMessage());
    }
}
